package com.niit.chat.controller;

import com.niit.chat.entity.Session;
import com.niit.chat.service.SessionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/sessions")
public class SessionController {

    @Autowired
    private SessionService sessionService;

    @GetMapping
    public List<Session> listSessions() {
        return sessionService.listSessions();
    }

    @GetMapping("/{id}")
    public Session getSession(@PathVariable Long id) {
        return sessionService.getSessionById(id);
    }

    @GetMapping("/user/{userId}")
    public List<Session> listSessionsByUser(@PathVariable Long userId) {
        return sessionService.listSessionsByUser(userId);
    }

    @PostMapping
    public void createSession(@RequestBody Session session) {
        sessionService.createSession(session);
    }

    @PutMapping("/{id}")
    public void updateSession(@PathVariable Long id, @RequestBody Session session) {
        session.setId(id);
        sessionService.updateSession(session);
    }

    @DeleteMapping("/{id}")
    public void deleteSession(@PathVariable Long id) {
        sessionService.deleteSession(id);
    }
} 